#include <iostream>

using namespace std;
typedef unsigned long NUM;

NUM ipow (NUM base, NUM exp)
{
    int result = 1;
    while (exp)
    {
        if (exp & 1)
            result *= base;
        exp >>= 1;
        base *= base;
    }
    return result;
}

NUM sum_pow (NUM num)
{
	int result = 0;
	while (num)
	{
		result += ipow(num%10, 5);
		num /= 10;
	}
	return result;
}

int main()
{
	NUM result = 0;

	for (NUM i = 2; i < 500000; i++)
	{
		if (i == sum_pow(i))
		{
			result += i;
			cout << i << endl;
		}
	}

	cout << result << endl;
	return 0;
}
